# project
cmake_minimum_required (VERSION 3.2.0)
project (libicp)

# directories
FIND_PATH(BOOST_DIR "boost")
find_package(Boost REQUIRED COMPONENTS system)
find_package(OpenMP)
if(OPENMP_FOUND OR OpenMP_FOUND)
	message(STATUS "using openmp")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

list(APPEND LIB_HEADERS
	./src/matrix.h
	./src/kdtree.h
	./src/icp.h
	./src/icpPointToPlane.h
	./src/icpPointToPoint.h)

add_library(${PROJECT_NAME}
	./src/kdtree.cpp
	./src/icp.cpp
	./src/icpPointToPoint.cpp
	./src/icpPointToPlane.cpp
	./src/matrix.cpp
	${LIB_HEADERS}
	)
target_include_directories(${PROJECT_NAME} PUBLIC
	$<INSTALL_INTERFACE: include>
	${BOOST_INCLUDE_DIRS}
	)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
	export(TARGETS ${PROJECT_NAME}
		FILE "${PROJECT_BINARY_DIR}/libicp-targets.cmake")
	export(PACKAGE ${PROJECT_NAME})
	
	set(EXPORT_TARGETS ${PROJECT_NAME} CACHE INTERNAL "export targets")
	set(CONFIG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libicp-config.cmake.in
		"${CMAKE_CURRENT_BINARY_DIR}/libicp-config.cmake" @ONLY)

	# build demo program
	find_package(Eigen3 REQUIRED)
	find_package(OpenCV REQUIRED)
	add_executable(icp ./test/test2d.cpp)
	target_include_directories(icp PUBLIC
		${OpenCV_INCLUDE_DIRS}
		${EIGEN3_INCLUDE_DIRS}
		src)
	target_link_libraries(icp
		${OpenCV_LIBRARIES}
	libicp)
endif()
